const { Recipes, Ingredients, Steps, Nutrition } = require('./database');

// 封装一个异步函数来插入数据
async function seedData() {
  try {
    // 插入食谱数据
    const recipe = await Recipes.create({
      name: '番茄炒蛋',
      image_url: 'https://example.com/tomato-egg.jpg',
      description: '一道经典的家常菜，口感鲜美，营养丰富。',
      prep_time: 10,
      cook_time: 15,
      servings: 2
    });

    // 插入食材数据
    const ingredients = await Ingredients.bulkCreate([
      {
        recipe_id: recipe.id,
        name: '番茄',
        amount: '2',
        unit: '个'
      },
      {
        recipe_id: recipe.id,
        name: '鸡蛋',
        amount: '3',
        unit: '个'
      },
      {
        recipe_id: recipe.id,
        name: '盐',
        amount: '适量',
        unit: ''
      }
    ]);

    // 插入烹饪步骤数据
    const steps = await Steps.bulkCreate([
      {
        recipe_id: recipe.id,
        step_number: 1,
        instruction: '将番茄洗净，切成小块。'
      },
      {
        recipe_id: recipe.id,
        step_number: 2,
        instruction: '将鸡蛋打入碗中，加入少许盐，搅拌均匀。'
      },
      {
        recipe_id: recipe.id,
        step_number: 3,
        instruction: '热锅凉油，倒入鸡蛋液，炒熟盛出。'
      },
      {
        recipe_id: recipe.id,
        step_number: 4,
        instruction: '锅中再倒少许油，放入番茄块翻炒至变软。'
      },
      {
        recipe_id: recipe.id,
        step_number: 5,
        instruction: '倒入炒好的鸡蛋，翻炒均匀，加入适量盐调味即可。'
      }
    ]);

    // 插入营养信息数据
    const nutrition = await Nutrition.create({
      recipe_id: recipe.id,
      calories: 300,
      protein: 15.00,
      fat: 18.00,
      carbs: 12.00
    });

    console.log('数据插入成功');
  } catch (error) {
    console.error('插入数据时出错:', error);
  }
}

// 调用函数
// seedData();
module.exports = { seedData };
